<template>
  <div>
    <el-dialog
            :visible.sync="dialogVisible.v"
            :page="currentPage"
            v-dialogDrag
            v-on:click="getGMData">
      <div>
        <v_myForm v-on:getGeeParam="getGMData" :page="modelPage" :form_list="Modelparams" :dialogVisible.sync="dialogVisible" :artifactId="artifactId" :currentItemId="currentItemId" ref="myForm"></v_myForm>
      </div>
    </el-dialog>
  </div>
</template>

<script>
    import myForm from '../form/modelForm';


    export default {
        name: "model-dialog",
        data() {
            return {
                geeModelParams: [],
                Modelparams: [],
                formData: [],
                dialogVisible: Object,
                artifactId: '',
                currentItemId: '',
                jobName: '',
                modelPage: ''
            }
        },
        components: {
            "v_myForm": myForm,
        },
        props: {
            currentPage: String
        },
        methods: {
            initParallelModel() {
                this.Modelparams = [];
                let obj = this;
                this.$axios.get('/parallel/get/' + this.artifactId)
                    .then((res) => {
                        let modelpara = [];
                        let parm = JSON.parse(res.body.parameters);
                        // let geeParam = [];
                        //过滤只有一个输入数据源的参数
                        // if (param.in <= 0) {
                        //     continue;
                        // } else {
                        //     geeParam.push(param);
                        // }
                        if (this.currentPage !== 'gee') {
                            modelpara = [{
                                "default": "default",
                                "datatype": "String",
                                "name": "任务名称",
                                "description": "一个SPARK任务的名称"
                            }];
                            this.Modelparams = modelpara.concat(JSON.parse(res.body.parameters));
                        } else if (this.currentPage == 'gee') {
                            this.modelPage = 'gee';
                            // modelpara = [{"default":"default","datatype":"String","name":"空间范围","description":"方法执行的空间范围"}];
                            // this.Modelparams = modelpara.concat(geeParam);
                            // this.Modelparams = JSON.parse(res.body.parameters).concat(modelpara);
                            this.Modelparams = JSON.parse(res.body.parameters);
                        }
                    }).catch(function (error) {
                        console.log(error);
                        obj.$message.error('模型参数获取失败!');
                });
                if (this.$refs.myForm)
                    this.$refs.myForm.reset();
            },
            getGMData(data) {
                this.$emit("totalModelParam", data);
            },

        },
        mounted() {
            this.$Bus.$on('pop', (dialogVisible, artificatId, currentItemId) => {
                this.dialogVisible = dialogVisible;
                this.artifactId = artificatId;
                this.currentItemId = currentItemId;
                this.initParallelModel();
            })
        },
    }
</script>
<style>
    .el-dialog__body {
        padding: 0px 20px 20px 20px;
    }
</style>
